home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / db2_stru.cq / db2_stru.c
Encoding:
C/C++ Source or Header  |  1985-12-01  |  4.3 KB  |  167 lines

  1. #include "stdio.h"
  2.  
  3. #define ERROR 0  /*  error constant       */
  4. #define EOF 13   /*  dBASE II EOF marker  */
  5.  
  6. /************************************************************************/
  7. /*  This program is designed to list the structure of any dBASE II file.*/
  8. /*  If you would like more information on how to access dBASE II files  */
  9. /*  & dBASE II indexes send $35.00 to:                                  */
  10. /*                                                                      */
  11. /*                        ANDERSON COMPUTER-WARE                        */
  12. /*                        P. O. BOX 8116                                */
  13. /*                        SPRINGFIELD, MO  65801                        */
  14. /*                                                                      */
  15. /*  Written by: Kelly C. Anderson, June 1984                            */
  16. /************************************************************************/
  17.  
  18. main (argc, argv)
  19.    int argc;
  20.    char **argv;
  21. {
  22.    FILE *fd, *fopen();
  23.    int pos, high, low, records, month, day, year, lhigh, llow, length;
  24.    int counter, width, decimal, j;
  25.    int c;
  26.    char fd1 [10];
  27.    char fd2 [14];
  28.    char name[], desc [10];
  29.    char type[], field [1];
  30.  
  31. /*  Get the file name from the keyboard  */
  32.  
  33.    if (argc != 2)
  34.    {
  35.       printf ("This program will display any dBASE II file structure.\n\n");
  36.       printf ("Enter the dBASE file name now without its extension: ");
  37.       scanf ("%s", fd1);
  38.    } else
  39.       strcpy (fd1, argv[1]);
  40.  
  41. /*  Add to the file name the ".DBF" extension.  */
  42.  
  43.    strncpy (fd2,fd1,10);
  44.    strcat (fd2,".DBF");
  45.  
  46. /*  Capitalize the inputted file name.  */
  47.  
  48.    cap (fd2);
  49.  
  50. /*  Check to make sure the file exists.  */
  51.  
  52.    if ((fd = fopen (fd2,"r")) == ERROR)
  53.       printf ("\n\nNo such file %s!!!   Program aborting.", fd2);
  54.    else{
  55.  
  56. /*  Check to make sure the file is a dBASE II file.  */
  57.  
  58.       c = getc (fd);
  59.       if (c != 2)
  60.       {
  61.          printf ("\n\n%s is not a dBase II file!!! Program aborting.", fd2);
  62.       }else{
  63.          printf ("\nSTRUCTURE FOR FILE:  %s", fd2);
  64.  
  65. /*  Find out how many records are in the file  */
  66.  
  67.          c = getc (fd);
  68.          low = c;
  69.          c = getc (fd);
  70.          high = c;
  71.          records = low + high * 256;
  72.          printf ("\nNUMBER OF RECORDS:   %d", records);
  73.  
  74. /*  Get the date the last changes were made */
  75.  
  76.          c = getc (fd);
  77.          month = c;
  78.          c = getc (fd);
  79.          day = c;
  80.          c = getc (fd);
  81.          year = c;
  82.          printf ("\nDATE OF LAST UPDATE: %d/%d/%d", month, day, year);
  83.  
  84. /*  Get the record length of each record  */
  85.  
  86.          c = getc (fd);
  87.          llow = c;
  88.          c = getc (fd);
  89.          lhigh = c;
  90.          length = llow + lhigh * 256;
  91.          printf ("\nRECORD LENGTH:       %d bytes", length);
  92.          printf ("\nFLD       NAME    TYPE WIDTH  DEC\n");
  93.  
  94. /*  Begin listing the structure onto the console  */
  95.  
  96.          counter = 1;
  97.  
  98.          while ((c = getc (fd)) != EOF)
  99.          {
  100.             name[0] = c;
  101.  
  102. /*  Get the field description  */
  103.  
  104.  
  105.             for (j=1; j<10; j++)
  106.             {
  107.                c = getc (fd);
  108.                name[j] = c;
  109.             }
  110.  
  111.             strncpy (desc, name, 10);
  112.  
  113. /*  Get the type of field  */
  114.  
  115.             c = getc (fd);
  116.             c = getc (fd);
  117.             type[0] = c;
  118.             strncpy (field, type, 1);
  119.  
  120. /*  Get the length of the field  */
  121.  
  122.             c = getc (fd);
  123.             width = c;
  124.  
  125. /*  Get the decimal length of the field if the field is numeric  */
  126.  
  127.             c = getc (fd);
  128.             c = getc (fd);
  129.             c = getc (fd);
  130.             decimal = c;
  131.  
  132. /*  Display information onto screen  */
  133.  
  134.             printf ("%3d    %-10s  %1s    %3d   %3d\n", counter, desc, field,
  135.                width, decimal);
  136.             counter++;
  137.          }
  138.       }
  139.    }
  140.  
  141. /*  Display logo & close the files  */
  142.  
  143.    printf ("\n--Anderson Computer-Ware--\n");
  144.    exit ();
  145. }
  146.  
  147.  
  148.  
  149. /*  This section will capitalize the variable passed to it  */
  150.  
  151. cap (nstr)
  152.  
  153. char *nstr;
  154.  
  155. {
  156.    int i;
  157.  
  158.    nstr [0] = toupper (nstr [0]);
  159.    for (i = 0; i < 13; i++)
  160.       nstr [i+1] = toupper (nstr [i+1]);
  161.  
  162. }
  163. {
  164.    int i;
  165.  
  166.    nstr [0] = toupper (nstr [0]);
  167.    for (i = 0; i < 13; i++)